package services.sbk_jjgl;

import java.util.HashMap;
import java.util.List;
import com.PublicSystem;
/**
 * 成品卡验登记
 * @author host
 *
 */
public class CpkysServices {
	PublicSystem sys = PublicSystem.getInstance();	
	/**
	 * 查询制卡信息
	 * 
	 * @author duy
	 * @param obj
	 * @param parms
	 * @throws Exception
	 */
	public HashMap getWxk(Object[] obj, HashMap parms) throws Exception {
		String sql = "select * from az20 where " +
				"('" + obj[0] + "' is null or aaz001 = ? )" +
				"and (aaz723='7' or aaz723='5') " +
				"and aaz718 is not null " +
				"and aaz732 is null " +
				"and ('" + obj[1] + "' is null or aae008 = ? )" +
				"order by aab001,aac001";
		HashMap map = sys.getGrid(sql, obj, parms, false);
		return map;
	}	
	/**
	 * 数据插入临时表zj_tmp
	 * @author duy
	 * @param obj
	 * @throws Exception
	 */
	public String insertTmp(HashMap obj ) throws Exception {
		String sql = "insert into zj_tmp(eventid,eventtype,c1,c2,c3) values('" + obj.get("eventid") + "'," +
				"'" + obj.get("eventtype") + "','" + obj.get("aac001") + "','" + obj.get("aae008") + "','" + obj.get("aaz723") + "')";
		sys.executeSql(sql);
		return "";
	} 	
	/**
	 * 保存数据，利用存储过程获取
	 * @author duy
	 * @param obj
	 * @throws Exception
	 */
	public String insertWzk(HashMap obj ) throws Exception {
		String ss = sys.callDBFuncProce("ic_az20.set_cpkysdj","function", obj);
		String[] str = ss.split("&");
		return str[0];		
	} 	
	/**
	 * 下拉框数据取得
	 * 
	 * @author duy
	 * @param
	 * @throws Exception
	 */
	public List getSelect(String AAA100) throws Exception {
		String sql = "SELECT AAA102,AAA103 FROM AA10 where AAA100=?";
		List data = sys.query(sql, new Object[] { AAA100 }, true);
		return data;
	}	
	/**
	 * 下拉框数据取得卡厂
	 * 
	 * @author duy
	 * @param
	 * @throws Exception
	 */	
	public List getselectKC() throws Exception {
		String sql = "SELECT AZF030,AZF031 FROM AZ52";
		List data = sys.query(sql, new Object[] {}, true);
		return data;
	}	
	/**
	 * 下拉框数据取得未制卡等
	 * 
	 * @author duy
	 * @param
	 * @throws Exception
	 */
	public List getselectWzk(String AAA100) throws Exception {
		String sql = "SELECT AAA102,AAA103 FROM v_ic_az11 where AAA100=?";
		List data = sys.query(sql, new Object[] { AAA100 }, true);
		return data;
	}
	public HashMap getUnitData(String id,String aaz001) {
		String sql = "select * from az20 where AAC001 = ? and AAZ001=?";	
		List data = sys.query(sql, new Object[] {id,aaz001}, true);	
		/*HashMap map=new HashMap();
		if(data.size()==0){
			map.put("error","该批次不存在该人员或者该人员已经验证！");
		}else{
			map.put("error","");
			map=(HashMap)data.get(0);
		}*/
		return data.size()>0 ?(HashMap)data.get(0):null;
	}
	public String getvalue(HashMap map) throws Exception {
		String ss = sys.callDBFuncProce("ic_az20.chk_cpkysjc","function", map);
		String[] str = ss.split("&");
		ss=str[0];
		if("0".equals(ss)){
			String str1 = sys.SelResultStr("select chr(1) from dual");
		    String str2 = sys.SelResultStr("select chr(2) from dual");
		    String[] res=str[1].split(str1);
		    String aa=res[0];
		    String bb=res[1];
		    String[] res1=aa.split(str2);
		    String azf030=res1[1];
		    String[] res2=bb.split(str2);
		    String aaz704=res2[1];
		    ss=azf030+","+aaz704;
		}
		return ss+",";
	}
	public void insertzj_tem(HashMap map3, String eventid) throws Exception {
		String sql = "insert into zj_tmp(eventid,eventtype,c1,c2,c3) values('" + eventid + "'," +
				"'bank','" + map3.get("aac008") + "','" + map3.get("aaz709") + "','" + map3.get("aaz710") + "')";
		sys.executeSql(sql);
	}
}
